<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/layouts/include/taglib.jsp" %> 

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta name="decorator" content="default" />

<script >
var saveTeam = function(){
	var sb = new StringBuffer();
	$('#form-field-select-2 option:selected').each(function(i, selected) {
		var value = $(selected).val();
		sb.append(";").append(value);

		}); 
	var str = sb.toString().substring(1);//获得人员编号字符串，分号分隔

	 Otod.ajax({
		url:"${ctx}/pm/team/saveTeam.do?prjId="+prjId+"&roleNo1="+"01"+";"+$('#form-field-select-1 option:selected').val()+"&roleNo2="+"02"+";"+str,
		successFn:function(data){
			
			Otod.Msg.info("保存成功");
		}
	}); 
}




</script>
</head>
<body >

<form class="col-sm-12">
		<div class="col-xs-12 col-sm-4">
			<div class="widget-box">
				<div class="widget-header">
					<h4>成员设置</h4>

				</div>
				
				<div class="widget-body">
					<div class="widget-main">
						<div>
							<label for="form-field-select-1">项目经理</label>
							<select class="form-control" id="form-field-select-1">
							</select>
						</div>
						<div>
							<label for="form-field-select-2">项目成员</label>
							<select multiple="" class="width-80 chosen-select" id="form-field-select-2" data-placeholder="Choose a Member...">
								
							</select>
						</div>
					</div>
					<div class="col-md-offset-2 col-md-9">
						<button class="btn btn-info" type="button" id="submit" onClick=saveTeam();>
							<i class="icon-ok bigger-110"></i>
							Submit
						</button>
	
						
						<button class="btn" type="reset">
							<i class="icon-undo bigger-110"></i>
							Reset
					</button>
				</div>
				</div>
				
				
				
			</div>
		</div><!-- /span -->
		
</form>

<script type="text/javascript">
var prjId = "${param.prjId}";
var empList = "";
$(document).ready(function() {
	$(".chosen-select").chosen(); 
	Otod.ajax({
		url:"${ctx}/sys/emp/findAll.do?",
		contentType: "application/x-www-form-urlencoded;",
		successFn:function(data){
			empList = data;
			var html = "";
			for(var i=0;i<data.length;i++){
				html =  html +  "<option value=\""+data[i].empNo+"\">"+data[i].empName+"</option>";
			}
			$("#form-field-select-1").html(html);
			$('#form-field-select-2').html(html);
			
			$('#form-field-select-2').trigger("chosen:updated.chosen");
		}
	});
	
	
	$("button[type='reset']").click(function(e){
	    setTimeout(function(){ $(".chosen-select").trigger("chosen:updated.chosen"); }, 50);
	});
	
	
	Otod.ajax({
		url:"${ctx}/pm/team/findByPrjId.do?prjId="+prjId,
		contentType: "application/x-www-form-urlencoded;",
		successFn:function(data){
			$.each(data,function(i,t){
				
				if(t.roleNo=="01"){
					$("#form-field-select-1").val(t.empNo);
				}else if(t.roleNo=="02"){
					$("#form-field-select-2 option[value='"+t.empNo+"']").attr("selected","selected");
				}
			});
			$('#form-field-select-2').trigger("chosen:updated.chosen");
		}
	});
	
})
</script>

</body>

